//
//  HDCFAlreadyHaveCell.m
//  HaoDeCaiFu
//
//  Created by 郑开宏 on 2017/10/31.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "HDCFAlreadyHaveCell.h"

@interface  HDCFAlreadyHaveCell()
@property (weak, nonatomic) IBOutlet UIImageView *imgView;
@property (weak, nonatomic) IBOutlet UILabel *titleLa;
@property (weak, nonatomic) IBOutlet UILabel *moneyL;
@property (weak, nonatomic) IBOutlet UILabel *earnL;
@property (weak, nonatomic) IBOutlet UILabel *timeL;
@property (weak, nonatomic) IBOutlet UILabel *moneyLOne;
@property (weak, nonatomic) IBOutlet UILabel *timeLOne;
@property (weak, nonatomic) IBOutlet UILabel *earnOne;

@end

@implementation HDCFAlreadyHaveCell

- (void)setDataDict:(NSDictionary *)dataDict{
    _dataDict = dataDict;
    if(dataDict[@"portfolioName"]){
        CGFloat money = 0.0;
        CGFloat yearterdayEarn = 0.0;
        NSDictionary *dict = dataDict[@"fundHoldings"];
        NSArray * array = [NSArray arrayWithArray:dict[@"data"]];
        for (int i = 0; i < array.count; i++) {
            NSDictionary *fundDict = array[i];
            NSNumber *currentValue = fundDict[@"currentValue"];
            money = money + currentValue.doubleValue;
            NSNumber *previousProfitLoss = fundDict[@"previousProfitLoss"];
            yearterdayEarn = yearterdayEarn + previousProfitLoss.doubleValue;
            
            
        }
        _moneyL.text = [NSString stringWithFormat:@"%.2f", money];
        _timeL.text = [NSString stringWithFormat:@"%.2f", yearterdayEarn];
        _imgView.image = [UIImage imageNamed:@"zuhe"];
        
        
        
        //基金数量
        _titleLa.text = dataDict[@"portfolioName"];
        _earnOne.text = @"基金数量";
        _earnL.text = [NSString stringWithFormat:@"%ld", array.count];
    }else{

        _earnOne.text = @"最新净值";
    
        
        _titleLa.text = dataDict[@"fundName"];
        if (![dataDict[@"currentValue"] isKindOfClass:[NSNull class]]) {
            NSNumber *currentValue = dataDict[@"currentValue"];
            _moneyL.text = [NSString stringWithFormat:@"%.2f", currentValue.doubleValue];
        }

        
        if ([dataDict[@"fundType"] isEqualToString:@"collective"]) {
            _imgView.image = [UIImage imageNamed:@"licai"];
            _titleLa.text = dataDict[@"fundName"];
            if (![dataDict[@"currentValue"] isKindOfClass:[NSNull class]]) {
                NSNumber *currentValue = dataDict[@"currentValue"];
                _moneyL.text = [NSString stringWithFormat:@"%.2f", currentValue.doubleValue];
            }else{
                _moneyL.text = @"0.00";
            }
            if (![dataDict[@"nav"] isKindOfClass:[NSNull class]]) {
                NSNumber *nav = dataDict[@"nav"];
                _earnL.text = [NSString stringWithFormat:@"%.4f", nav.doubleValue];
            }else{
                _earnL.text = @"0.0000";
            }
            
            if (![dataDict[@"previousProfitNLoss"] isKindOfClass:[NSNull class]]) {
                NSNumber *previousProfitNLoss = dataDict[@"previousProfitNLoss"];
                _timeL.text = [NSString stringWithFormat:@"%.2f", previousProfitNLoss.doubleValue];
            }else{
                _timeL.text = @"正在计算";
            }

        }else{
            _imgView.image = [UIImage imageNamed:@"jijin"];
            _titleLa.text = dataDict[@"fundName"];
            if (![dataDict[@"currentValue"] isKindOfClass:[NSNull class]]) {
                NSNumber *currentValue = dataDict[@"currentValue"];
                _moneyL.text = [NSString stringWithFormat:@"%.2f", currentValue.doubleValue];
            }else{
                _moneyL.text = @"0.00";
            }
            if (![dataDict[@"nav"] isKindOfClass:[NSNull class]]) {
                NSNumber *nav = dataDict[@"nav"];
                _earnL.text = [NSString stringWithFormat:@"%.4f", nav.doubleValue];
            }else{
                _earnL.text = @"0.0000";
            }
            
            if (![dataDict[@"previousProfitNLoss"] isKindOfClass:[NSNull class]]) {
                NSNumber *previousProfitNLoss = dataDict[@"previousProfitNLoss"];
                _timeL.text = [NSString stringWithFormat:@"%.2f", previousProfitNLoss.doubleValue];
            }else{
                _timeL.text = @"正在计算";
            }
        }
        
        
    }
}

+ (instancetype)HDCFAlreadyHaveCell{
    return [[NSBundle mainBundle] loadNibNamed:@"HDCFAlreadyHaveCell" owner:nil options:nil].firstObject;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
